class zk < Formula
  desc "Centralized server for distributed coordination of services"
  homepage "https://zookeeper.apache.org/"
  url "https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz"
  mirror "https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz"
  sha256 "476f6fce10f9528e3a4ad00e6cd1714563f602dd4924db78e506c0df28fea1e5"
  license "Apache-2.0"
  revision 1
  head "https://gitbox.apache.org/repos/asf/zookeeper.git"

  bottle do
    sha256 cellar: :any, big_sur: "476f6fce10f9528e3a4ad00e6cd1714563f602dd4924db78e506c0df28fea1e5"
  end

  def default_zk_env
    <<~EOS
      [ -z "$ZOOCFGDIR" ] && export ZOOCFGDIR="#{etc}/zookeeper"
    EOS
  end

  def default_log4j_properties
    <<~EOS
      log4j.rootCategory=WARN, zklog
      log4j.appender.zklog = org.apache.log4j.RollingFileAppender
      log4j.appender.zklog.File = #{var}/log/zookeeper/zookeeper.log
      log4j.appender.zklog.Append = true
      log4j.appender.zklog.layout = org.apache.log4j.PatternLayout
      log4j.appender.zklog.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
    EOS
  end

  def install
    system "tar", "-xf", "apache-zookeeper-3.6.2-bin.tar.gz"
    binpfx = "apache-zookeeper-3.6.2-bin"

    bin.mkpath
    (etc / binpfx + "/bin").mkpath
  end

end
